home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / k3bversion.h < prev    next >
Encoding:
C/C++ Source or Header  |  2008-05-27  |  4.6 KB  |  142 lines

  1. /* 
  2.  *
  3.  * $Id: k3bversion.h 619556 2007-01-03 17:38:12Z trueg $
  4.  * Copyright (C) 2003 Sebastian Trueg <trueg@k3b.org>
  5.  *
  6.  * This file is part of the K3b project.
  7.  * Copyright (C) 1998-2007 Sebastian Trueg <trueg@k3b.org>
  8.  *
  9.  * This program is free software; you can redistribute it and/or modify
  10.  * it under the terms of the GNU General Public License as published by
  11.  * the Free Software Foundation; either version 2 of the License, or
  12.  * (at your option) any later version.
  13.  * See the file "COPYING" for the exact licensing terms.
  14.  */
  15.  
  16.  
  17. #ifndef _K3B_VERSION_H_
  18. #define _K3B_VERSION_H_
  19.  
  20. #include <qstring.h>
  21. #include "k3b_export.h"
  22. /**
  23.  * \brief Representation of a version.
  24.  *
  25.  * K3bVersion represents a version consisting of a major version (accessible via majorVersion()),
  26.  * a minor version (accessible via minorVersion()), a patchLevel (accessible via patchLevel()),
  27.  * and a suffix (accessible via suffix()).
  28.  *
  29.  * The major version is mandatory while all other fields are optional (in case of the minor version 
  30.  * and the patchlevel -1 means that the field is undefined).
  31.  *
  32.  * K3bVersion tries to treat version suffixes in an "intelligent" way to properly compare versions
  33.  * (see compareSuffix() for more details).
  34.  *
  35.  * K3bVersion may also be used everywhere a QString is needed as it automatically converts to a
  36.  * string representation using createVersionString().
  37.  */
  38. class LIBK3B_EXPORT K3bVersion 
  39. {
  40.  public:
  41.   /**
  42.    * construct an empty version object
  43.    * which is invalid
  44.    * @ see isValid()
  45.    */
  46.   K3bVersion();
  47.  
  48.   /**
  49.    * copy constructor
  50.    */
  51.   K3bVersion( const K3bVersion& );
  52.  
  53.   /**
  54.    * this constructor tries to parse the given version string
  55.    */
  56.   K3bVersion( const QString& version );
  57.  
  58.   /**
  59.    * sets the version and generates a version string from it
  60.    */
  61.   K3bVersion( int majorVersion, int minorVersion, int pachlevel = -1, const QString& suffix = QString::null );
  62.  
  63.   /**
  64.    * tries to parse the version string
  65.    * used by the constructor
  66.    */
  67.   void setVersion( const QString& );
  68.  
  69.   bool isValid() const;
  70.  
  71.   /**
  72.    * sets the version and generates a version string from it
  73.    * used by the constructor
  74.    *
  75.    * If minorVersion or pachlevel are -1 they will not be used when generating the version string.
  76.    */
  77.   void setVersion( int majorVersion, int minorVersion = -1, int patchlevel = -1, const QString& suffix = QString::null );
  78.  
  79.   const QString& versionString() const { return m_versionString; }
  80.   int majorVersion() const { return m_majorVersion; }
  81.   int minorVersion() const { return m_minorVersion; }
  82.   int patchLevel() const { return m_patchLevel; }
  83.   const QString& suffix() const { return m_suffix; }
  84.  
  85.   /**
  86.    * just to make it possible to use as a QString
  87.    */
  88.   operator const QString& () const { return m_versionString; }
  89.   K3bVersion& operator=( const QString& v );
  90.  
  91.   /**
  92.    * \return A new K3bVersion object which equals this one except that the suffix is empty.
  93.    */
  94.   K3bVersion simplify() const;
  95.  
  96.   /**
  97.    * If minorVersion or pachlevel are -1 they will not be used when generating the version string.
  98.    * If minorVersion is -1 patchlevel will be ignored.
  99.    */
  100.   static QString createVersionString( int majorVersion, 
  101.                       int minorVersion = -1, 
  102.                       int patchlevel = -1, 
  103.                       const QString& suffix = QString::null );
  104.  
  105.   /**
  106.    * "Intelligent" comparison of two version suffixes.
  107.    *
  108.    * This method checks for the following types of suffixes and treats them in the
  109.    * following order:
  110.    *
  111.    * [empty prefix] > rcX > preX > betaX > alphaX = aX (where X is a number)
  112.    *
  113.    * Every other suffixes are compared alphanumerical.
  114.    * An empty prefix is always considered newer than an unknown non-emtpy suffix (e.g. not one of the above.)
  115.    *
  116.    * @return \li -1 if suffix1 is less than suffix2
  117.    *         \li 0 if suffix1 equals suffix2 (be aware that this is not the same as comparing to strings as 
  118.    *             alphaX equals aX in this case.)
  119.    *         \li 1 if suffix1 is greater than suffix2
  120.    */
  121.   static int compareSuffix( const QString& suffix1, const QString& suffix2 );
  122.  
  123.  private:
  124.   static void splitVersionString( const QString& s, int& num, QString& suffix );
  125.  
  126.   QString m_versionString;
  127.   int m_majorVersion;
  128.   int m_minorVersion;
  129.   int m_patchLevel;
  130.   QString m_suffix;
  131. };
  132.  
  133.  
  134. LIBK3B_EXPORT bool operator<( const K3bVersion& v1, const K3bVersion& v2 );
  135. LIBK3B_EXPORT bool operator>( const K3bVersion& v1, const K3bVersion& v2 );
  136. LIBK3B_EXPORT bool operator==( const K3bVersion& v1, const K3bVersion& v2 );
  137. LIBK3B_EXPORT bool operator<=( const K3bVersion& v1, const K3bVersion& v2 );
  138. LIBK3B_EXPORT bool operator>=( const K3bVersion& v1, const K3bVersion& v2 );
  139.  
  140.  
  141. #endif
  142.